layui.use(['table', 'admin', 'ax', 'laytpl','jquery','laydate','form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laytpl = layui.laytpl;
    var laydate = layui.laydate;
    var form = layui.form;

    /**
     * 工程流水
     */
    var TaskFlow = {
        tableId: "taskFlowTable"
    };


    var ajax1 = new $ax(Feng.ctxPath + "/project/selectYyjlList", function (data) {
        var sb;
        for(let i = 0; i < data.length; i++) {
            sb+='<option>' + data[i].yyjl + '</option>';
        }
        $("#yyjl").append(sb);
        form.render();
    }, function (data) {
        Feng.error(data.responseJSON.message);
    });
    ajax1.start();

    //渲染时间选择框
    laydate.render({
        elem: '#timeLimit',
        range: true,
        tiger: 'click',
        // max: Feng.currentDate()
    });

    /**
     * 初始化表格的列
     */
    TaskFlow.initColumn = function () {
        return [[
            {field: 'id', hide: true, title: '工程id'},
            {align: 'center', type: "numbers", title: '序号', style:'font-size:11px',width: 50},
            {field: 'name', sort: true, title: '工程名称',align: "left", width: 350},
            //开发总监
            // //{field: 'kfzj', sort: true, title: '开发总监',align: "center", width: 200},
            // {templet: '#kfzjTpl', sort: true, title: '开发总监',align: "center",width: 200 },
            // //2
            // //{field: 'gczj', sort: true, title: '工程总监',align: "center", width: 200},
            // {templet: '#gczjTpl', sort: true, title: '工程总监',align: "center",width: 200 },
            // //3
            //{field: 'yyzj', sort: true, title: '营运总监',align: "center",width: 160 },
             {templet: '#yyzjTpl', sort: true, title: '营运总监',align: "left"},
            //4
            // {field: 'allotYy', sort: true, title: '指定营运经理',align: "center",width: 160 },
            {templet: '#statusTpl1', sort: true, title: '营运经理',align: "left"},
            //5
            //{field: 'allotDd', sort: true, title: '指定督导',align: "center",width: 160},
            // {templet: '#statusTpl2', sort: true, title: '指定督导',align: "center",width: 160 },
            // //6
            // {field: 'dudao', sort: true, title: '督导',align: "center",width: 160},
            //7完工
            // {field: 'gcb', sort: true, title: '完工',align: "center" },
             //{templet: '#statusTpl3', sort: true, title: '开店状态',align: "center" },

            {field: 'status', sort: true, title: '状态', align: "left", templet:function(d){
                    switch (d.status) {
                        case 1: return '新建中';break;
                        case 2: return '审批中';break;
                        case 3: return '对接中';break;
                        case 4: return '装修中';break;
                        case 5: return '筹备中';break;
                        case 6: return '已开业';break;
                    }
                }},

            {templet: '#statusTpl4', sort: true, title: '开业日期',align: "left"},
            // {align: 'center', toolbar: '#tableBar', title: '操作', align: "center", minWidth: 150}

        ]];
    };

    TaskFlow.tabCfg={
        elem: '#' + TaskFlow.tableId,
        data:[],
        page: true,
        even: true,
        cellMinWidth: 100,
        cols: TaskFlow.initColumn()
    };
    var  para = sessionStorage.getItem("gclbcxList");
    if(para!=null){
        var p=JSON.parse(para);
        TaskFlow.tabCfg.url= Feng.ctxPath + '/task/yingYunQuery';
        TaskFlow.tabCfg.where=p;
        if(p.name!=''){
            $('#condition').val(p.name);
        }
        if(p.yyjl!=''){
            $('#yyjl').val(p.yyjl);
        }
        if(p.timeLimit!=''){
            $('#timeLimit').val(p.timeLimit);
        }
        form.render('select');
    }

    // 渲染表格
    var tableResult = table.render(TaskFlow.tabCfg);

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        TaskFlow.search();
    });

    /**
     * 点击查询按钮
     */
    TaskFlow.search = function () {
        var queryData = {};
        queryData['name'] = $("#condition").val();
        queryData['yyjl'] = $("#yyjl").val();
        queryData['timeLimit'] = $("#timeLimit").val();
        queryData['status'] = $("#status").val();
        queryData['endYn'] = $("#endYn").val();
        queryData['cashierAccountYn'] = $("#cashierAccountYn").val();
        // table.reload(TaskFlow.tableId, {where: queryData});
        TaskFlow.tabCfg.url= Feng.ctxPath + '/task/yingYunQuery';
        TaskFlow.tabCfg.where= queryData;
        table.render(TaskFlow.tabCfg);
        sessionStorage.setItem("gclbcxList",JSON.stringify(queryData));
    };

    TaskFlow.search();
    /**
     * 查看流水明细
     */
    TaskFlow.flowChart = function (data) {
        window.location.href = Feng.ctxPath + '/project/proFlowChart?id=' + data.id;
    };

    // 工具条点击事件
    table.on('tool(' + TaskFlow.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'flowChart') {
            TaskFlow.flowChart(data);
        }
    });
});
